﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace WindowsService
{
    class ServiceTask
    {
        private readonly string DailyStartTime = ConfigurationManager.AppSettings["DailyStartTime"];

        public void TaskSwitcher(DateTime currentTime)
        {
            string longtime = currentTime.ToLongTimeString();
            ServiceEmail sendEmail = new ServiceEmail();
            try
            {
                if (longtime == DailyStartTime)
                {
                    if (currentTime.Day == 1)
                    {
                        sendEmail.SendDailyEmail(currentTime);
                        if (currentTime.DayOfWeek.ToString() == "Monday" || currentTime.DayOfWeek.ToString() == "星期一")
                            sendEmail.SendWeeklyEmail(currentTime);
                        sendEmail.SendMonthlyEmail(currentTime);
                    }
                    else if (currentTime.DayOfWeek.ToString() == "Monday" || currentTime.DayOfWeek.ToString() == "星期一")
                    {
                        sendEmail.SendDailyEmail(currentTime);
                        sendEmail.SendWeeklyEmail(currentTime);
                    }
                    else
                    {
                        sendEmail.SendDailyEmail(currentTime);
                    }
                }
            }
            catch (Exception e)
            {
                LogHandle.WriteErrorLog(e);
            }
            
        }

    }
}
